package com.dtw.ditouwang.ui.mine;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dtw.ditouwang.R;
import com.dtw.ditouwang.beans.RankingBean;
import com.dtw.ditouwang.models.WebApi;

import java.util.List;

public class RankingAdapter extends RecyclerView.Adapter<RankingAdapter.Holder>{
    private List<RankingBean.DataBean.OrderDataBean> orderDataBeanList;

    public RankingAdapter(List<RankingBean.DataBean.OrderDataBean> orderDataBeanList ){

        this.orderDataBeanList = orderDataBeanList;
    }
    @NonNull
    @Override
    public Holder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new Holder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_ranking,viewGroup,false));
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int i) {
        holder.textName.setText(orderDataBeanList.get(i).getNickname());
        holder.textDistance.setText(orderDataBeanList.get(i).getMileage()+"公里");
        if(!TextUtils.isEmpty(orderDataBeanList.get(i).getHead())) {
            Glide.with(holder.userHead).load(WebApi.BaseUrl + orderDataBeanList.get(i).getHead().replace("\\", "/")).into(holder.userHead);
        }else{
            holder.userHead.setImageBitmap(null);
        }
        if(orderDataBeanList.get(i).getOrder_number()==1){
            holder.imgRanking.setImageResource(R.drawable.icon_ranking_firsk);
            holder.textRanking.setText(null);
        }else if(orderDataBeanList.get(i).getOrder_number()==2){
            holder.imgRanking.setImageResource(R.drawable.icon_ranking_second);
            holder.textRanking.setText(null);
        }else if(orderDataBeanList.get(i).getOrder_number()==3){
            holder.imgRanking.setImageResource(R.drawable.icon_ranking_third);
            holder.textRanking.setText(null);
        }else{
            holder.textRanking.setText(orderDataBeanList.get(i).getOrder_number()+"");
            holder.imgRanking.setImageBitmap(null);
        }
    }

    @Override
    public int getItemCount() {
        return orderDataBeanList.size();
    }

    class Holder extends RecyclerView.ViewHolder{
        TextView textName,textDistance,textRanking;
        ImageView userHead,imgRanking;
        public Holder(@NonNull View itemView) {
            super(itemView);
            textName = itemView.findViewById(R.id.text_name);
            textDistance = itemView.findViewById(R.id.text_distance);
            textRanking = itemView.findViewById(R.id.text_ranking_num);
            imgRanking = itemView.findViewById(R.id.img_ranking);
            userHead = itemView.findViewById(R.id.img_head);
        }
    }
}
